var QRCodePage = Vue.component('qrCodePage', function (resolve, reject) {
    axios.get('views/QRCode/QRCode.html?timestamp=' + timestamp).then(function (res) {
        resolve({
            template: res.data,
            data(){
                return {
                    needAdminRole:CommonUtils.checkRole('admin'),
                    needAliMgrRole:CommonUtils.checkRole("alipay"),
                    tableData: [],
                    dialogVisible:false,
                    pageInfo:{
                        srchType:"2",
                        currentPage:1,
                        pageSize:10,
                        srch_EQ_isDelete:false,
                        srch_LIKE_name:'',
                        totalNum:10,
                        "srch_JOINEQ_roles.code":'sales'
                        // "srch_JOINEQ_aliLifes.id":['e4c0ae6f6b5b37cb016b5b3ca5450001']
                    },
                    editForm:{},
                    detailForm:{
                        createBy:{
                            name:''
                        }
                    },
                    subProducts:[],
                    showEditWin:false,
                    showDetailWin:false,
                    showResetPwdWin:false,
                    allLifes:[],
                    checkedLifes:[],
                    formLabelWidth: '150px',
                    resetPwdForm:{},
                    expandRow:[],
                    currentSalesId:'',
                    currentSalesName:'',
                    qrcodeTitle:'',
                    qrCodeBGImgUrl:MAIN_INFO_CONFIG.qrCodeBGImgUrl,
                    tempData:[],
                    originalFlag :false
                }
            },
            methods:{

                handleCurrentChange: function(currentPage){
                    this.pageInfo.currentPage = currentPage;
                    this.initData();
                },
                initData:function(){
                    var loginUser = JSON.parse(sessionStorage.loginUser);

                    if(CommonUtils.checkRole('sales')){
                        this.pageInfo.srch_EQ_id=loginUser.id;
                    }
                    if(CommonUtils.checkRole('alipay')){
                        this.pageInfo.srch_EQ_id='';
                        this.pageInfo['srch_JOINEQ_aliLifes.id']=CommonUtils.productSrchLifeIds();

                    }
                    httpInvoker.get(APIs.auser.initPageData,{
                        params:this.pageInfo,
                        paramsSerializer: params => {
                            return Qs.stringify(params, { indices: false })
                        }
                    }).then(res =>{
                        // console.log(res.data);
                        if(res.status == 200 && res.data.status == '00'){
                            this.allLifes = res.data.data.allLifes;
                            this.tableData = res.data.data.lifeMgrs.content;
                            this.pageInfo.totalNum=res.data.data.lifeMgrs.totalElements;

                            if(CommonUtils.checkNotNull(this.tableData)){
                                for (let ti = 0; ti < this.tableData.length; ti++) {
                                    this.tableData[ti].products = []
                                }
                            }

                        }else{
                            this.$alert(res.data.msg, '', {
                                confirmButtonText: '确定'
                            });
                        }
                    })
                },
                handleExpandChange(row, expandedRows) {
                    this.currentSalesId=row.id;
                    this.currentSalesName = row.name;
                    this.subProducts = [];
                    httpInvoker.get(APIs.product.findBySales,{params:{
                            suid:row.id
                        }}).then(res =>{
                        if(res.status == 200 && res.data.status == '00'){
                            this.subProducts = res.data.data;
                        }else{
                            this.$alert(res.data.msg, '', {
                                confirmButtonText: '确定'
                            });
                        }
                    })
                    if(this.expandRow.length == 1 && this.expandRow[0] == row.id){
                        return;
                    }
                    this.expandRow= [];
                    this.expandRow.push(row.id);
                    // console.log(this.$refs);
                    // this.$refs.subTable.toggleRowExpansion(row, false) // 点击button展开

                },

                openDetails(row){
                    this.dialogVisible=true;
                    var domObj = document.getElementById('div-QRCode');
                    if(CommonUtils.checkNotNull(domObj)){
                        domObj.innerHTML = "";
                    }
                    this.qrcodeTitle="商品:"+row.name+" 话务员:"+this.currentSalesName;
                    var cpage = this;
                    setTimeout(function () {
                        jQuery('#div-QRCode').qrcode({
                            render: "canvas",
                            text: qrcodeUrl+"?productId="+row.id+"&salesId="+cpage.currentSalesId,
                            width: "180",               //二维码的宽度
                            height: "180",           //二维码的高度
                            background: "#ffffff",      //二维码的后景色
                            foreground: "#000000" ,     //二维码的前景色
                            src: MAIN_INFO_CONFIG.qrCodeLogo            //二维码中间的图片
                        });
                    },1000)

                },openDetailsURL(row){
                    var base64 = new BASE64();
                    var ps = "&t="+base64.encode(MAIN_INFO_CONFIG.appTitle);
                    ps = ps+"&m="+base64.encode(MAIN_INFO_CONFIG.qrCodeBGImgUrl);
                    ps = ps+"&m1="+base64.encode(MAIN_INFO_CONFIG.qrCodeLogo);
                    var url =location.origin+"/"+bizCode+"/user_data/share/share.html"+"?productId="+row.id+"&salesId="+this.currentSalesId;
                    url = url+ps
                    window.open(url);
                },
                getRowKey(row){
                    return row.id;
                },originalQRocde(row){
                    this.dialogVisible=true;
                    var domObj = document.getElementById('div-QRCode');
                    if(CommonUtils.checkNotNull(domObj)){
                        domObj.innerHTML = "";
                    }
                    this.qrcodeTitle="商品:"+row.name+" 话务员:"+this.currentSalesName;
                    var cpage = this;
                    setTimeout(function () {
                        jQuery('#div-QRCode').qrcode({
                            render: "canvas",
                            text: qrcodeUrl+"?productId="+row.id+"&salesId="+cpage.currentSalesId,
                            width: "180",               //二维码的宽度
                            height: "180",           //二维码的高度
                            background: "#ffffff",      //二维码的后景色
                            foreground: "#000000" ,     //二维码的前景色
                            src: MAIN_INFO_CONFIG.qrCodeLogo            //二维码中间的图片
                        });
                    },1000)
                }



            },
            mounted: function () {
                this.initData();
            },
        })
    })
})